<template>
	<view>
		<view style="padding: 30rpx;">
			<view class="u-flex u-font-weight  " style="color: #FF5D39;margin: 40rpx 0;font-size: 34rpx;">
				{{$orderType(info.orderType)}}设计—
				{{info.status==2?'待处理':info.status==3?'估价中':info.status==4?'设计中':info.status==6?'已完成':info.status==5?'二次修改':''}}
			{{info.finish?'-已完结':''}}
			</view>
			
			
			<view class="mode u-margin-bottom-20" v-if="info.status==4">
				<view class="u-flex u-row-between u-margin-bottom-20">
					<view class="$u-type-info">设计总价</view>
					<view class="$u-type-error">￥{{info.designMoney}}</view>
				</view>
				
				<view class="u-flex u-row-between">
					<view class="$u-type-info">支付金额</view>
					<view class="$u-type-error">￥{{info.unpaidMoney}}</view>
				</view>
				
			</view>
			
			
			<!-- 文件 -->
			<view class="mode u-margin-bottom-20">
				<view class="u-flex u-row-between " v-for="(item,index) in info.dl" :key="index" v-if="item.status">
					<view class="u-flex">
						<u-image src="/static/file.png" width="160" height="160"></u-image>
						<view class="u-margin-left-20">
							<view>设计文件</view>
							<view class="u-margin-top-20">请下载查看哦！</view>
						</view>
					</view>
					
					<u-button size="mini" shape="circle" type="error" @click="look(item)">查看</u-button>
				</view>
			</view>
			

			<view class="bg u-margin-bottom-20"  v-if="info.status==6">
				<view>
					<view>设计规则</view>
					<view>首次免费修改，多次修改每次￥{{buyDesignReferFee}}</view>
				</view>
			</view>
			
			<view class="bg"  v-if="info.status==3">
				<view>需要支付费用</view>
				<view style="font-size: 40rpx;">￥{{info.unpaidMoney}}</view>
			</view>
			
			<view class="bg"  v-if="info.status==4">
				<view>
					<view>您的设计需求已发送给设计师</view>
					<view> 请耐心等待设计结果哦~可免费修改一次</view>
				</view>
			</view>
			
			
			
			<view class="mode">
				<view class="u-flex u-row-between u-row-center">
					<view class="u-font-weight">设计需求</view>
					<view class="$u-type-info">{{info.createTime}}</view>
				</view>
				<view class="u-margin-top-20 u-margin-bottom-20">{{info.remark}}</view>
				<view class="u-flex">
					<view v-for="(item,index) in info.image" :key="index" class="u-margin-right-20">
						<u-image :src="item" width="150" height="150"></u-image>
					</view>
				</view>
			</view>
			
		</view>
		
		<!-- 已完成 -->
		<view  v-if="info.status==6 && !info.finish"
	
			style="background: #fff; border-top: 1rpx solid #e1e1e1; padding: 20rpx; position: fixed;z-index: 999;bottom: 0;display: flex;justify-content: space-around;width: 100%;">
			<u-button @click="apply" shape="circle" :custom-style="{background:'#FFA843',color:'#fff',}">
				申请修改</u-button>
	
			<u-button shape="circle" @click="end"  :custom-style="{background:'#FF5D39',color:'#fff',}">
				结束服务</u-button>
		</view>
		
		
		<!-- 估价中 -->
		<view  v-if="(info.status==3 || info.status==5 ) && Number(info.unpaidMoney) >0 "
			style="background: #fff; border-top: 1rpx solid #e1e1e1; padding: 20rpx; position: fixed;z-index: 999;bottom: 0;display: flex;justify-content: space-around;width: 100%;">
			<u-button  @click="buy" shape="circle" :custom-style="{background:'#FFA843',color:'#fff',}">
				直接支付￥{{info.unpaidMoney}}</u-button>
			<u-button  v-if="info.status==3 " shape="circle" @click="kanjia"  :custom-style="{background:'#FF5D39',color:'#fff',}">
				去砍价</u-button>
		</view>
		<u-top-tips ref="uTips"></u-top-tips>
		<u-toast ref="uToast" />
	</view>
</template>

<script>
	import payway from '@/common/wxpay.js';
	export default{
		data(){
			return{
				id:"",
				info:{},
				buyDesignReferFee:'' ,  //设计组讯飞
				banShare:true,
				buyVideoPrice:"", //视频钱
			}
		},
		onLoad(options) {
			if(options.id){
			   this.id=options.id
			}
			
			
			this.$u.api.Commission().then(res=>{
				this.buyDesignReferFee=Number(res.buyDesignReferFee).toFixed(2)
				this.buyVideoPrice=  Number(res.buyVideoPrice).toFixed(2) 
			})
		},
		onShow() {
			this.jiazai()
		},
		methods:{
			look(item){
				uni.navigateTo({
					url:"./fileDetail?item="+JSON.stringify(item)  
				})
			},
			
			jiazai(){
				this.$u.post('/indent/orderDetail', {
					order_id:this.id
				}).then(res => {
					this.info = res
				}).catch(err => {
				
				})
			},
			buy(){
				this.$u.post('/indent/pay', {
					order_id:this.id
				}).then(res => {
					if (!Array.isArray(res) ) {
						var packages = res.package;
						var {
							noncestr,
							timestamp,
							signtype,
							paysign
						} = res
						payway.wx(timestamp, noncestr, packages, signtype, paysign).then(res => {     
                           this.$refs.uToast.show({
							title: '支付成功',
							type: 'success',
							back:true
						})
						}).catch(err => {
							
						})
					} else {
						this.$refs.uToast.show({
							title: '支付成功',
							type: 'success',
							back:true
						})
					}
					
					
					
				}).catch(err => {
				
				})
			},
			end(){
				uni.showModal({
					title:"温馨提示",
					content:  `只需${ this.buyVideoPrice}元,直接生成视频哦~~`,  
					cancelText:"不用了",
				    confirmText:"支付",
					success:(res)=> {	
						if(res.confirm){
							this.$u.post('/indent/makeOrderVideo', {
								order_id:this.id
							}).then(res => {
								if (!Array.isArray(res) ) {
									var packages = res.package;
									var {
										noncestr,
										timestamp,
										signtype,
										paysign
									} = res
									payway.wx(timestamp, noncestr, packages, signtype, paysign).then(res => {     
								       this.$refs.uToast.show({
								       	title: '生成成功',
								       	type: 'success',
								       	back:true,
										callback :()=>{
											this.$u.post('/indent/finish', {
												order_id:this.id
											}).then(res => {
												this.$refs.uTips.show({
																title: '请至【看视频】——【视频订单】查看视频制作情况哦~',
																type: 'success',
																duration: '2300'
															})
											}).catch(err => {
											
											})
																		
										}
								       })
									}).catch(err => {
										
									})
								} else {
									this.$refs.uToast.show({
										title: '生成成功',
										type: 'success',
										back:true,
										callback :()=>{
											this.$u.post('/indent/finish', {
												order_id:this.id
											}).then(res => {
												this.$refs.uTips.show({
																title: '请至【看视频】——【视频订单】查看视频制作情况哦~',
																type: 'success',
																duration: '2300'
															})
											}).catch(err => {
											
											})
										}
									})
								}
								

							}).catch(err => {
							
							})
						}else{
							// this.$u.post('/indent/finish', {
							// 	order_id:this.id
							// }).then(res => {
							// 	this.$refs.uTips.show({
							// 					title: '请至【看视频】——【视频订单】查看视频制作情况哦~',
							// 					type: 'success',
							// 					duration: '2300'
							// 				})
							// }).catch(err => {
							
							// })
							
						}
						
					}
				})
			},
			kanjia(){
				uni.navigateTo({
					url:"./kanjia?id="+this.id
				})
			},
			apply(){
				uni.navigateTo({
					url:"./applyChange?id="+this.id+'&changeNum='+this.info.changeNum
				})
			}
			
		}
	}
</script>

<style>
	.bg{
		background:#FF5D39;
		padding: 20rpx 40rpx;
		border-radius: 20rpx;
		color: #fff;
		display: flex;
		justify-content: space-between;
		align-items: center;
		
		
	}
</style>
